import { request } from '../request';

// 企业信息API类型（文件字段为单图URL字符串，非数组）
export namespace Api.SystemCompany {
  export interface CompanyInfo {
    companyName: string;
    companyPhone: string;
    companyEmail: string;
    officialAccountLink: string;
    companyLogo: string | null;
    officialAccountImg: string | null;
  }

  // 文件上传响应
  export interface UploadResponse {
    url: string;
    fileName?: string;
  }
}

// 获取企业信息
export function fetchGetCompanyInfo() {
  return request<Api.SystemCompany.CompanyInfo>({
    url: '/systemCompany/getCompanyInfo',
    method: 'get'
  });
}

// 保存企业信息
export function fetchSaveCompanyInfo(data: Api.SystemCompany.CompanyInfo) {
  return request<boolean>({
    url: '/systemCompany/saveCompanyInfo',
    method: 'post',
    data
  });
}

// 上传文件
export function fetchUploadFile(
  file: File,
  fileType: 'companyLogo' | 'officialAccountImg'
) {
  const formData = new FormData();
  formData.append('file', file);
  formData.append('fileType', fileType);

  return request<Api.SystemCompany.UploadResponse>({
    url: '/systemCompany/uploadFile',
    method: 'post',
    data: formData,
    headers: { 'Content-Type': 'multipart/form-data' }
  });
}
